package com.qezhhnjy.mall.coupon.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qezhhnjy.mall.common.entity.coupon.CouponSpuCategoryRelation;
import com.qezhhnjy.mall.common.http.BaseResult;
import com.qezhhnjy.mall.coupon.service.CouponSpuCategoryRelationService;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 优惠券分类关联 前端控制器
 * </p>
 *
 * @author qezhhnjy
 * @since 2021-06-27
 */
@RestController
@Api(tags = "优惠券分类关联接口")
@Slf4j
@RequestMapping("/coupon-spu-category-relation")
public class CouponSpuCategoryRelationController {
    @Resource
    private CouponSpuCategoryRelationService couponSpuCategoryRelationService;

    @GetMapping("/get")
    @Operation(summary = "根据id获取优惠券分类关联信息")
    public BaseResult<CouponSpuCategoryRelation> get(Long id) {
        CouponSpuCategoryRelation couponSpuCategoryRelation = couponSpuCategoryRelationService.getById(id);
        return BaseResult.success(couponSpuCategoryRelation);
    }

    @PostMapping("/save")
    @Operation(summary = "新增优惠券分类关联信息")
    public BaseResult<CouponSpuCategoryRelation> save(@RequestBody CouponSpuCategoryRelation couponSpuCategoryRelation) {
        couponSpuCategoryRelationService.save(couponSpuCategoryRelation);
        return BaseResult.success(couponSpuCategoryRelation);
    }

    @PutMapping("/update")
    @Operation(summary = "更新优惠券分类关联信息")
    public BaseResult<CouponSpuCategoryRelation> update(@RequestBody CouponSpuCategoryRelation couponSpuCategoryRelation) {
        couponSpuCategoryRelationService.updateById(couponSpuCategoryRelation);
        return BaseResult.success(couponSpuCategoryRelation);
    }

    @PostMapping("/page")
    @Operation(summary = "分页获取优惠券分类关联信息")
    public BaseResult<Page<CouponSpuCategoryRelation>> page(@RequestBody Page<CouponSpuCategoryRelation> page) {
        couponSpuCategoryRelationService.page(page);
        return BaseResult.success(page);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "根据id删除优惠券分类关联信息")
    public BaseResult<Long> delete(Long id) {
        couponSpuCategoryRelationService.removeById(id);
        return BaseResult.success(id);
    }
}

